﻿using System;
namespace Xroad.Eu.Xsd.Identifiers {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="XRoadLocalGroupIdentifierType", Namespace="http://x-road.eu/xsd/identifiers", Target=typeof(XRoadLocalGroupIdentifierType))]
    public class XRoadLocalGroupIdentifierTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected XRoadLocalGroupIdentifierType clazz;
        
        public XRoadLocalGroupIdentifierTypeSerializer(XRoadLocalGroupIdentifierType clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXmlAttributes(Writer);
            if ((clazz.ObjectType != null)) {
                Writer.WriteAttributeString(Writer.LookupPrefix("http://x-road.eu/xsd/identifiers"), "objectType", "http://x-road.eu/xsd/identifiers", new global::Xroad.Eu.Xsd.Identifiers.XRoadObjectType(clazz.ObjectType).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.AttributeRequiredException(">>XRoadLocalGroupIdentifierType>objectType");
            }
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement(Writer.LookupPrefix("http://x-road.eu/xsd/identifiers"), "groupCode", "http://x-road.eu/xsd/identifiers");
            if (clazz.GroupCode!=null) {
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.GroupCode))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : GroupCode");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXmlAttributes(Reader);
            var objectTypeValue = Reader.GetAttribute("objectType", "http://x-road.eu/xsd/identifiers");
            if ((objectTypeValue != null)) {
                clazz.ObjectType = new global::Xroad.Eu.Xsd.Identifiers.XRoadObjectType(objectTypeValue);
            }
            else {
                throw new global::Xtee.Core.Exceptions.AttributeRequiredException(">>XRoadLocalGroupIdentifierType>objectType");
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="groupCode") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>groupCode");
                }
                clazz.GroupCode = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("groupCode", "http://x-road.eu/xsd/identifiers")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>groupCode", Reader.LocalName);
            }
        }
    }
}
